home *** CD-ROM | disk | FTP | other *** search
- /*
- CDPlay1 - An XCMD to play an audio track and stop.
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/15 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDPlay1.c
- link -sn Main=CDPlay1 -sn STDIO=CDPlay1 ∂
- -sn INTENV=CDPlay1 -rt XFCN=42 ∂
- -m CDPlay1 CDPlay1.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- void ExtractTrackNo(char *, short *);
- OSErr APlay(XCmdBlockPtr, short, short);
- OSErr AStop(short, short);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDPlay1
- *
- * Purpose: play an audio track
- *
- * Returns: result of driver call to play track
- * normally 0, but could have parameter error or
- * other error if non-existent track is specified
- *
- * Side Effects:
- *
- * Description: We need one parameter, the track number. Get
- * the global ioRefNum that we set by
- * previously calling CDOpen(). Extract the
- * track number and play it.
- *
- ************************************************************************/
- pascal void
- CDPlay1(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short trackNumber;
- short ioRefNum;
- Handle refHandle;
-
- /* Must be one parameter */
- if ((paramPtr->paramCount) != 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- /* First param is track number. Convert it to a pascal string */
- ExtractTrackNo((char *)*(paramPtr->params[0]), &trackNumber);
-
- result = AStop(trackNumber, ioRefNum);
-
- if (result == noErr)
- result = APlay(paramPtr, trackNumber, ioRefNum);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
- /************************************************************************
- *
- * Function: ExtractTrackNo
- *
- * Purpose: Extract track number in BCD from PString
- *
- * Returns: nothing
- *
- * Side Effects: *track gets a new value
- *
- * Description: Extract track number in BCD from Cstring "name".
- * "name" is always of the form "XX", where XX
- * ranges from "1" to "99"
- * (You can't have more than 99 tracks on a compact disc.
- * Bet you didn't know that, did you? Right in the "Yellow
- * Book" specification of compact disc encoding.)
- *
- ************************************************************************/
- void
- ExtractTrackNo(name, track)
- char *name;
- short *track;
- {
- short t;
-
- t = 0;
- while (*name != 0)
- {
- t *= 16;
- t += *name - '0';
- name++;
- }
-
- *track = t;
- }
-
- /************************************************************************
- *
- * Function: APlay
- *
- * Purpose: start playing an audio track
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: starts play. By default, this will play until the
- * end of the disc.
- *
- * Description: The track that you pass in is the first track that you
- * want to have play.
- *
- ************************************************************************/
- OSErr
- APlay(paramPtr, track, refNum)
- XCmdBlockPtr paramPtr;
- short track;
- short refNum;
- {
- struct {
- short addrFormat;
- long address;
- short stopAddress;
- short playMode;
- } csParam;
- short playMode;
- Handle refHandle;
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, PLAYMODE);
- playMode = atoi(*(refHandle));
- DisposHandle(refHandle);
-
- csParam.addrFormat = TRACKADDR;
- csParam.address = track; /* must be in BCD */
- csParam.stopAddress = 0;
- csParam.playMode = playMode;
- return (Control(refNum, APLAY, &csParam));
- }
-
-
- /************************************************************************
- *
- * Function: AStop
- *
- * Purpose: stop playing an audio track
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: stops play.
- *
- * Description: The track that you pass in is the LAST track that you
- * want to have play. This means that if you wanted to
- * play only one track, you'd pass the same value to
- * this routine and APlay() [q.v.]
- *
- * Note that this routine isn't called in this sample,
- * but it's included for your enjoyment.
- *
- ************************************************************************/
- OSErr
- AStop(track, refNum)
- short track;
- short refNum;
- {
- struct {
- short addrFormat;
- long address;
- } csParam;
-
- csParam.addrFormat = TRACKADDR;
- csParam.address = track;
- return (Control(refNum, ASTOP, &csParam));
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-